function _new() {
    let obj = new Object(); // 1. 创建一个新对象
    let Constructor = [].shift.call(arguments); // 借用数组的方法，取出参数中的构造函数
    obj.__proto__ = Constructor.prototype; // 2. 将构造函数的this指向新对象
    let ret = Constructor.apply(obj, arguments) // 3. 为新对象添加属性
    return typeof ret === 'object' ? ret : obj; // 4. 返回新对象
}

// 版本二，借助ES6
function _new(obj, ...rest) {
    // 基于obj的原型创建一个新的对象
    const newObj = Object.create(obj.prototype);
    const result = obj.apply(newObj, rest);

    return typeof result === 'object' ? result : newObj;
}


function Person(name, age) {
    this.name = name;
    this.age = age;
    this.sex = 'male';
}
Person.prototype.isHandsome = true;
Person.prototype.sayName = function() {
    console.log(`Hello , my name is ${this.name}`);
}

let handsomeBoy = _new(Person, 'lynn', 24);

console.log(handsomeBoy.name) // lynn
console.log(handsomeBoy.sex) // male
console.log(handsomeBoy.isHandsome) // true

handsomeBoy.sayName(); // Hello , my name is lynn